import ReactDOM from 'react-dom'

export default function addEventListenerWrap(target: HTMLElement, eventType: any,
    cb: any, option: boolean | AddEventListenerOptions): any {
  const callback = ReactDOM.unstable_batchedUpdates
    ? (e: any) => ReactDOM.unstable_batchedUpdates(cb, e) : cb
  if (target.addEventListener) {
    target.addEventListener(eventType, callback, option)
  }
  return {
    remove: () => {
      if (target.removeEventListener) {
        target.removeEventListener(eventType, callback)
      }
    }
  }
}